<extend name="Common/base" />

<block name="content">
    <div id="login-box">
        <form id="login-form" name="login-form" class="form-vertical" action="/login" method="post">
            <table border="0" cellpadding="0" cellspacing="0">
                <tbody>
                <tr>
                    <td colspan="3">
                        <div class="control-group normal-text">
                            <h3>
                                <img src="http://123.57.22.77/ui/img/logo1.png"/>
                            </h3>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="main-input-box">
                            <span class="add-on bg_lg">
                                <i class="icon-user"></i>
                            </span>
                        </div>
                    </td>
                    <td colspan="2">
                        <div class="main-input-box text-left">
                            <input name="email" type="text" value="" placeholder="输入您的Email">
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="3" class="height-30"></td>
                </tr>
                <tr>
                    <td>
                        <div class="main-input-box">
                            <span class="add-on bg_ly">
                                <i class="icon-lock"></i>
                            </span>
                        </div>
                    </td>
                    <td colspan="2">
                        <div class="main-input-box text-left">
                            <input name="password" type="password" value="" placeholder="输入您的密码">
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="3" class="height-30"></td>
                </tr>
                <tr>
                    <td>
                        <div class="main-input-box">
                            <span class="add-on bg_ly">
                                <i class="icon-user"></i>
                            </span>
                        </div>
                    </td>
                    <td>
                        <div class="main-input-box text-left-important">
                            <input name="captcha" type="text" value="" placeholder="验证码">
                        </div>
                    </td>
                    <td>
                        <img class="captcha" src="/captcha/generate" alt="captcha" />
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        <div class="form-actions">
                            <span class="pull-left">
                                <a href="#" class="flip-link btn btn-info" id="to-recover">忘记密码</a>
                            </span>
                            <span class="pull-right">
                                <input type="submit" class="btn btn-success" value="登入">
                            </span>
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
        </form>
        <form id="recover-form" name="recover-form" class="form-vertical" method="post">
            <p class="normal-text">密码找回。</p>
            <div class="controls">
                <div class="main-input-box">
                <span class="add-on bg_lo">
                    <i class="icon-envelope"></i>
                </span>
                    <input name="recover-email" type="text" placeholder="输入你的邮箱地址" value="" />
                </div>
            </div>
            <div class="form-actions">
            <span class="pull-left">
                <a href="#" id="to-login" class="flip-link btn btn-success">« 返回登录页</a>
            </span>
                <span class="pull-right">
                <a href="#" id="forget-password " class="btn btn-info">提交</a>
            </span>
            </div>
        </form>
    </div>
</block>
<block name="script">
    <script type="application/javascript">
        requirejs(['jquery', 'require', 'jqueryForm', 'prompt'], function ($) {
            var prompt = require('prompt');

            $('#to-recover').click(function(){

                $("#login-form").slideUp();
                $("#recover-form").fadeIn();
            });
            $('#to-login').click(function(){

                $("#recover-form").hide();
                $("#login-form").fadeIn();
            });

            //登录
            $('#login-form').ajaxForm(function (json) {
                if (json.error) {
                    prompt.error('登陆失败,账户或密码错误');
                    return;
                }

                prompt.alert($LANG.LOGIN_SUCCESS, 1000, function () {
                    document.location.href = '/home';
                });
            });

            $("#forget-Pwd").click(function(){
                var email = $("#txtemail");
                if(email.val()==""){
                    alert("请输入你注册的邮箱地址");
                    return false;
                }
                var reg=/^[a-zA-Z0-9]([a-zA-Z0-9]*[-_.]?[a-zA-Z0-9]+)+@([\w-]+\.)+[a-zA-Z]{2,}$/;
                if(!reg.test( email.val() ) ){
                    alert("邮箱格式不正确！");
                    return false;
                }

                $.ajax({
                    type:"POST",
                    url:'http://123.57.22.77/login/forgetpwd',
                    data:'email='+email.val(),
                    success:function(msg){
                        if(msg=='0'){
                            alert("你的邮箱不正确,请重试！");
                        }else{
                            alert("你的密码已经重置成功,请登录你的邮箱查看系统初始密码！");
                        }
                    },
                    error:function(){alert("验证错误！");}
                });
            });
        });
    </script>
</block>